#include "Complex.h"

Complex::Complex(int r, int i)
{
    real = r;
    imag  =i;
}

Complex Complex::operator+(const Complex &obj){

    Complex res;                       // 定义一个临时复数res
    res.real = this ->real + obj.real; // 如果res用this代替的话，会出现this值每次更新的情况，即c1值会改变！
    res.imag = this ->imag + obj.imag;
    return res;
}

Complex Complex::operator-(const Complex &obj){

    Complex res;
    res.real = this ->real - obj.real;
    res.imag = this ->imag - obj.imag;
    return res;
}

Complex Complex::operator*(const Complex &obj){

    Complex res;
    res.real = this ->real * obj.real - this ->imag * obj.imag;
    res.imag = this ->imag * obj.real + this ->real * obj.imag;
    return res;
}

void Complex::print(){
    std::cout << real << "+" << imag << "i" << std::endl;
}
